#Boa:Frame:Frame1

import wx
import string

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1CLEARBTN, wxID_FRAME1FROMTXT, wxID_FRAME1PANEL1, 
 wxID_FRAME1SENDBTN, wxID_FRAME1SHOWTEXT, wxID_FRAME1STATICTEXT1, 
 wxID_FRAME1STATICTEXT2, wxID_FRAME1STATICTEXT3, wxID_FRAME1SUBTEXT, 
 wxID_FRAME1TOTEXT, 
] = [wx.NewId() for _init_ctrls in range(11)]

class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(316, 160), size=wx.Size(617, 432),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(617, 432))

        self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
              pos=wx.Point(0, 0), size=wx.Size(617, 432),
              style=wx.TAB_TRAVERSAL)

        self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
              label=u'From:', name='staticText1', parent=self.panel1,
              pos=wx.Point(96, 80), size=wx.Size(37, 17), style=0)

        self.staticText2 = wx.StaticText(id=wxID_FRAME1STATICTEXT2,
              label=u'To:', name='staticText2', parent=self.panel1,
              pos=wx.Point(104, 136), size=wx.Size(18, 17), style=0)

        self.fromtxt = wx.TextCtrl(id=wxID_FRAME1FROMTXT, name=u'fromtxt',
              parent=self.panel1, pos=wx.Point(144, 80), size=wx.Size(152, 27),
              style=0, value=u'')

        self.totext = wx.TextCtrl(id=wxID_FRAME1TOTEXT, name=u'totext',
              parent=self.panel1, pos=wx.Point(144, 136), size=wx.Size(160, 27),
              style=0, value=u'')

        self.subtext = wx.TextCtrl(id=wxID_FRAME1SUBTEXT, name=u'subtext',
              parent=self.panel1, pos=wx.Point(144, 176), size=wx.Size(320, 27),
              style=0, value=u'')

        self.staticText3 = wx.StaticText(id=wxID_FRAME1STATICTEXT3,
              label=u'Subject:', name='staticText3', parent=self.panel1,
              pos=wx.Point(72, 184), size=wx.Size(52, 17), style=0)

        self.showtext = wx.TextCtrl(id=wxID_FRAME1SHOWTEXT, name=u'showtext',
              parent=self.panel1, pos=wx.Point(144, 232), size=wx.Size(320,
              184), style=wx.TE_MULTILINE, value=u'')

        self.sendbtn = wx.Button(id=wxID_FRAME1SENDBTN, label=u'Send',
              name=u'sendbtn', parent=self.panel1, pos=wx.Point(504, 176),
              size=wx.Size(85, 29), style=0)
        self.sendbtn.Bind(wx.EVT_BUTTON, self.OnSendbtnButton,
              id=wxID_FRAME1SENDBTN)

        self.clearbtn = wx.Button(id=wxID_FRAME1CLEARBTN, label=u'Clear',
              name=u'clearbtn', parent=self.panel1, pos=wx.Point(512, 248),
              size=wx.Size(85, 29), style=0)
        self.clearbtn.Bind(wx.EVT_BUTTON, self.OnClearbtnButton,
              id=wxID_FRAME1CLEARBTN)

    def __init__(self, parent):
        self._init_ctrls(parent)
        

    def OnSendbtnButton(self, event):
        showtest=self.showtext.GetValue()
        fromadd=self.fromtxt.GetValue()
        toadd=self.totext.GetValue()
        subje=self.subtext.GetValue()
        body=None
        body=string.join((
            "From: %s" %fromadd,
            "To: %s" %toadd,
            "Sub: %s" %subje,
            " ",
            showtest),'\r\n')  
        self.Refresh()
        print self.showtext.SetValue(body)
        try:
            import smtplib
            serversmtp=smtplib.SMTP('smtp.gmail.com')
            serversmtp.ehlo()
            serversmtp.starttls()
            serversmtp.ehlo()
            serversmtp.login('yexiaotingzj','kfjatrtf')
            serversmtp.sendmail(fromadd,[toadd],self.showtext.GetValue())
            wx.MessageBox("Finish!")
            serversmtp.close()
        except:
            wx.MessageBox("sorry!")
            
        
        
        #event.Skip()

    def OnClearbtnButton(self, event):
        self.showtext.SetValue("")
        #event.Skip()
        
